package jrmob.yonyou.com.commonlib.baseManager;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/****
 * 描述: 本地数据库
 *
 * @author zhangg
 * @下午3:28:28
 */
public class DBHelper_lib extends SQLiteOpenHelper {

    /***
     * 数据库名称
     */
    public static final String DATABASE_NAME = "mob.db";
    /***
     * 最近联系人表名称
     */
    public static final String recentlyContacts = "recentlycontacts";


    /***
     * 我的审批
     */
    public static final String myApproveBills = "myapprovebills";


    /***
     * 数据库版本
     **/
    private static final int DATABASE_VERSION = 1;

    public DBHelper_lib(Context context, String name, SQLiteDatabase.CursorFactory factory,
                        int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {


        // 不存在的时候创建
        CreatemyApproveBillsTable(db);



    }

    /**
     * 构造函数
     *
     * @param context
     */
    public DBHelper_lib(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    /***
     * 创建 myApproveBillsTable
     *
     * @param db
     */
    public void CreatemyApproveBillsTable(SQLiteDatabase db) {
        // 如果已经存在先删除
        String deletesql = "drop table if  exists " + DBHelper_lib.recentlyContacts;
        db.execSQL(deletesql);


        // 创建表(如果不存在的话)
        String sql = "create table if not exists " + DBHelper_lib.myApproveBills
                + "(_id integer primary key autoincrement "
                + ", billid varchar(30)"
                + ", userid varchar(30)"
                + ", billno varchar(30)"
                + ", billtype varchar(30)"
                + ", billtypename varchar(30)"
                + ", procresult varchar(30)"
                + ", taskid varchar(30)"
                + ", ts varchar(30)"
                + ", unitshortname varchar(30)"
                + ", user_name varchar(20))";

        db.execSQL(sql);
    }






    /***
     * 创建最近联系人表
     *
     * @param db
     */
    public void createRecentlyContacts(SQLiteDatabase db) {
        // 如果已经存在先删除
        String deletesql = "drop table if  exists " + DBHelper_lib.recentlyContacts;
        db.execSQL(deletesql);
        // 创建表(如果不存在的话)
        String sql = "create table if not exists " + DBHelper_lib.recentlyContacts
                + "(_id integer primary key autoincrement, "
                + "user_name varchar(50) " + ", user_mobilephone varchar(20)"
                + ", user_telephone varchar(20)" + ", user_email varchar(20)"
                + ", cuserid varchar(20))";
        //db.execSQL(sql);
    }

    // 如果DATABASE_VERSION值被改为2,系统发现现有数据库版本不同,即会调用onUpgrade
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // db.execSQL("ALTER TABLE person ADD COLUMN other STRING");
    }

}
